#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define ISLESS(a, b) if ((a) != (b)) return (a) < (b)
#define ISGREATER(a, b) if ((a) != (b)) return (a) > (b)

vector <int> m_bookHeights;
vector <int> m_bookWidths;
vector <int> m_bookValues;

bool orderLess(int a, int b)
{
	ISLESS(m_bookHeights[a], m_bookHeights[b]);
	ISGREATER(m_bookValues[a], m_bookValues[b]);
	ISLESS(m_bookWidths[a], m_bookWidths[b]);
	return false;
}

class BookSelection
{
public:
	int GetPoints(vector <int> &result, vector <int> &values)
	{
		int n = result.size();	
		int res = 0;
		for (int i = 0; i < n; ++i)
			res += result[i] == -1 ? 0 : values[i];
		return res;
	}

	int GetPoints(int H, int W, vector <int> bookHeights, vector <int> bookWidths, vector <int> bookValues, double localCoef)
	{
		vector <int> localRes = arrange(H, W, bookHeights, bookWidths, bookValues, localCoef);
		return GetPoints(localRes, bookValues);
	}

	vector <int> arrange(int H, int W, vector <int> bookHeights, vector <int> bookWidths, vector <int> bookValues)
	{
		int n = 20;
		double a = 0, b = 1;
		for (int i = 1; i <= n; ++i)
		{
			double diff = (b - a) / 3;
			double c1 = a + diff;
			double c2 = b - diff;

			double val1 = GetPoints(H, W, bookHeights, bookWidths, bookValues, c1);
			double val2 = GetPoints(H, W, bookHeights, bookWidths, bookValues, c2);

			if (val1 > val2)
			{
				b = c2;
			}
			else
			{
				a = c1;
			}

		}

		return arrange(H, W, bookHeights, bookWidths, bookValues, 0.5 * (a + b));
	}

	vector <int> arrange(int H, int W, vector <int> bookHeights, vector <int> bookWidths, vector <int> bookValues, double coef)
	{
		m_bookHeights = bookHeights;
		m_bookWidths = bookWidths;
		m_bookValues = bookValues;

		int n = bookHeights.size();
		vector<int> order(n);
		for (int i = 0; i < n; ++i) order[i] = i;

		sort(order.begin(), order.end(), orderLess);

		static bool draw = true;
		if (draw) for (int t = 0; t < n; ++t)
		{
			int i = order[t];
			cerr << bookHeights[i] << "\t" << bookWidths[i] << "\t" << bookValues[i] << endl;
		}
		draw = false;

		int maxHeight = *max_element(bookHeights.begin(), bookHeights.end());

		int shelves = 1;
		int totalH = 10;
		int curMaxH = 0;
		int curW = 0;
		vector<int> result(n, -1);
		for (int t = 0; t < n; ++t)
		{
			int i = order[t];
			//if (curMaxH != 0 && bookHeights[i] > 2.0 * curMaxH) continue;
			//if (bookWidths[i] > coef * maxHeight) continue;
			if (bookHeights[i] > coef * maxHeight) continue;
			if (totalH + bookHeights[i] <= H)
			{
				if (curW + bookWidths[i] <= W)
				{
					result[i] = shelves - 1;
					curMaxH = max(curMaxH, bookHeights[i]);
					curW += bookWidths[i];
				}
				else
				{
					if (totalH + curMaxH + 10 <= H)
					{
						totalH = totalH + curMaxH + 10;
						curW = 0;
						curMaxH = 0;
						++shelves;
						--t;
					}
				}
			}
		}
	
		//cerr << "curW = " << curW << endl;
//		cerr << "X = " << n << endl;
//		cerr << "totalH = " << totalH + curMaxH << endl;
		return result;
	}
};

int nextInt()
{
	int n;
	cin >> n;
	return n;
}

void println(int n)
{
	cout << n << endl;
}

int main()
{
	int H = nextInt();
    int W = nextInt();
    int X = nextInt();
	vector<int> bookHeights(X);
    for(int i = 0; i<X; i++)
      bookHeights[i] = nextInt();
	vector<int> bookWidths(X);
    for(int i = 0; i<X; i++)
      bookWidths[i] = nextInt();
	vector<int> bookValues(X);
    for(int i = 0; i<X; i++)
      bookValues[i] = nextInt();
	BookSelection bs;
    vector<int> ret = bs.arrange(H, W, bookHeights, bookWidths, bookValues);
    for(int i = 0; i<X; i++)
      println(ret[i]);
	return 0;
}
